package com.hxkj.controller;

import com.hxkj.domain.po.Notice;
import com.hxkj.service.NoticeService;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import com.platform.common.domain.to.PageTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Callable;

/**
 * 公告控制器
 * <p>
 * Created by chenfangzhou on 2018/6/6.
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {


    @Autowired
    private NoticeService noticeService;


    /**
     * 获取公告列表
     *
     * @param notice
     * @return 翻页数据
     * @throws Exception
     */
    @RequestMapping(value = "/getlist", method = RequestMethod.POST)
    public Callable<ResultPageStruct<Notice>> getNoticeList(@ModelAttribute Notice notice, @ModelAttribute PageTo pageParam) throws Exception {
        return () -> noticeService.getNoticeList(notice == null ? new Notice() : notice, pageParam);
    }

    /**
     * 获取单一公告
     *
     * @param notice
     * @return friendlyLink
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public Callable<ResultDataStruct<Notice>> getNotice(@ModelAttribute Notice notice) throws Exception {
        return () -> noticeService.getNotice(notice);
    }


    /**
     * 新增角色
     *
     * @param notice
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ResultMessageStruct saveNotice(@ModelAttribute Notice notice) throws Exception {
        return noticeService.saveNotice(notice);
    }

    /**
     * 修改公告
     *
     * @param notice
     * @throws Exception
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    public ResultMessageStruct updateNotice(@ModelAttribute Notice notice) throws Exception {
        return noticeService.updateNotice(notice);
    }

    /**
     * 删除公告
     *
     * @param notice 公告信息
     * @throws Exception
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public ResultMessageStruct deleteNotice(@ModelAttribute Notice notice) throws Exception {
        return noticeService.deleteNotice(notice);
    }

}
